package com.kungkhies.mvc.feeds.view;

import static java.util.Arrays.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.feed.AbstractAtomFeedView;

import com.kungkhies.domain.kungkhie.KungkhieSummary;
import com.sun.syndication.feed.atom.Entry;

public class KungkhiesAtomView extends AbstractAtomFeedView
{
    @Override
    protected List<Entry> buildFeedEntries(
            Map<String, Object> model,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception
    {

        @SuppressWarnings("unchecked")
        List<KungkhieSummary> kungkhies = (List<KungkhieSummary>) model.get("kungkhies");
        List<Entry> entries = new ArrayList<Entry>();
        for (KungkhieSummary kungkhie : kungkhies)
        {
            Entry entry = new Entry();
            entry.setTitle(kungkhie.getText());
            entry.setCreated(kungkhie.getWhen());
            entry.setAuthors(asList(kungkhie.getKungkher().getFullName()));
            entries.add(entry);
        }

        return entries;
    }
}
